package by.amakarevich.services.impl;

import java.util.List;

import javax.inject.Inject;
import javax.persistence.metamodel.SingularAttribute;

import org.springframework.stereotype.Service;

import by.amakarevich.dataaccess.ShoppingCartInfoDao;
import by.amakarevich.datamodel.Product;
import by.amakarevich.datamodel.ShoppingCart;
import by.amakarevich.datamodel.ShoppingCartInfo;
import by.amakarevich.services.ShoppingCartInfoService;

@Service
public class ShoppingCartInfoServiceImpl  implements ShoppingCartInfoService {
	@Inject
	private ShoppingCartInfoDao shoppingCartInfoDao;
	
	@Override
	public void addNewShoppingCartInfo(ShoppingCartInfo shoppingCartInfo, Product product, ShoppingCart shoppingCart) {
		shoppingCartInfo.setProduct(product);
		shoppingCartInfo.setShoppingCart(shoppingCart);
		shoppingCartInfoDao.insert(shoppingCartInfo);
	}

	@Override
	public ShoppingCartInfo get(Long id) {
		return shoppingCartInfoDao.getById(id);
	}

	@Override
	public void updateShoppingCartInfo(ShoppingCartInfo shoppingCartInfo) {
		shoppingCartInfoDao.update(shoppingCartInfo);
	}

	@Override
	public void deleteShoppingCartInfo(Long id) {
		shoppingCartInfoDao.delete(id);
	}
	  
	@Override
	    public void deleteAll() {
		shoppingCartInfoDao.deleteAll();
	}
	
	@Override
	public List<ShoppingCartInfo> getAllShoppingCartInfo(){
		return shoppingCartInfoDao.getAllShoppingCartInfo();
	}
	
	@Override
    public List<ShoppingCartInfo> getAllShoppingCartInfoByShoppingCart(SingularAttribute<ShoppingCartInfo, ?> attr, boolean ascending, int startRecord, int pageSize){
    	return shoppingCartInfoDao.getAllShoppingCartInfoByShoppingCart(attr, ascending, startRecord, pageSize);
    }
	
	@Override
	public ShoppingCartInfo getShoppingCartInfo(ShoppingCart shoppingCart, Product product){
		return shoppingCartInfoDao.getShoppingCartInfo(shoppingCart, product);
	}
	
	@Override
	public List<ShoppingCartInfo> getAllByShoppingCart(ShoppingCart shoppingCart){
		return shoppingCartInfoDao.getAllByShoppingCart(shoppingCart);
	}
	
	@Override
	public ShoppingCartInfo getByShoppingCartId(Long shoppingCartInfoId){
		return shoppingCartInfoDao.getByShoppingCartId(shoppingCartInfoId);
	}
}

